package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodsKill;
import com.ruoyi.project.good.service.IGoodsKillService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品秒杀Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/kill")
public class GoodsKillController extends BaseController
{
    @Autowired
    private IGoodsKillService goodsKillService;

    /**
     * 查询商品秒杀列表
     */
    @PreAuthorize("@ss.hasPermi('good:kill:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsKill goodsKill)
    {
        startPage();
        List<GoodsKill> list = goodsKillService.selectGoodsKillList(goodsKill);
        return getDataTable(list);
    }

    /**
     * 导出商品秒杀列表
     */
    @PreAuthorize("@ss.hasPermi('good:kill:export')")
    @Log(title = "商品秒杀", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsKill goodsKill)
    {
        List<GoodsKill> list = goodsKillService.selectGoodsKillList(goodsKill);
        ExcelUtil<GoodsKill> util = new ExcelUtil<GoodsKill>(GoodsKill.class);
        return util.exportExcel(list, "kill");
    }

    /**
     * 获取商品秒杀详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:kill:query')")
    @GetMapping(value = "/{killId}")
    public AjaxResult getInfo(@PathVariable("killId") Long killId)
    {
        return AjaxResult.success(goodsKillService.selectGoodsKillById(killId));
    }

    /**
     * 新增商品秒杀
     */
    @PreAuthorize("@ss.hasPermi('good:kill:add')")
    @Log(title = "商品秒杀", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsKill goodsKill)
    {
        return toAjax(goodsKillService.insertGoodsKill(goodsKill));
    }

    /**
     * 修改商品秒杀
     */
    @PreAuthorize("@ss.hasPermi('good:kill:edit')")
    @Log(title = "商品秒杀", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsKill goodsKill)
    {
        return toAjax(goodsKillService.updateGoodsKill(goodsKill));
    }

    /**
     * 删除商品秒杀
     */
    @PreAuthorize("@ss.hasPermi('good:kill:remove')")
    @Log(title = "商品秒杀", businessType = BusinessType.DELETE)
	@DeleteMapping("/{killIds}")
    public AjaxResult remove(@PathVariable Long[] killIds)
    {
        return toAjax(goodsKillService.deleteGoodsKillByIds(killIds));
    }
}
